import { getIpStorage, setIpStorage } from "../storage.js";

let userInstance = null;

const userStore = function () {
  if (!userInstance) {
    const state = {
      ip: getIpStorage() || "",
    };

    const getters = {
      getIp() {
        return state.ip;
      },
    };

    const setters = {
      setIp(ip) {
        state.ip = ip;
        setIpStorage(ip);
      },
    };

    userInstance = {
      getters,
      setters,
    };
  }

  return userInstance;
};

export default userStore;
